home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 25
/
Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso
/
Aminet
/
util
/
rexx
/
SuperEval.lha
/
SuperEval
/
Eval.rexx
next >
Wrap
OS/2 REXX Batch file
|
1998-04-27
|
4KB
|
99 lines
/****
* Enhanced "c:Eval" Command
*
* With trig and other functions
* see REXXMATHLIB.library for fuction details
*
* syntax is the same as the rexxmathlib function calls
* ie: func(x[,y])
* OR spaces may be used as deliminators (in all funtions)
* ie: func x [y]
*
* There are two extra functions:
*
* 1) DEG(deg,min,sec) outputs Decimal degrees
* or the alternative syntax is DEG(dd.mmss)
*
* 2) DMS(DD.dddd) outputs dd mm ss
*
*
* If the function is unknown to rexxmathlib then the original line is
* passed, as typed, to the c:eval function. This alows for all the
* original "eval" maths (and syntax) to be used as a failsafe.
*
*
* Add the line
* Alias Eval rx rexx:eval.rexx []
* into the s:shell-startup script and use in any Shell
* syntax: eval func(x[,y]) OR as per dos EVAL command
* Put eval.rexx into rexx:
* and rexxmathlib.library into libs:
*
* NOTE: all angles are input as decimal DEGREES (NOT radians)
**/
call addlib('rexxmathlib.library',0,-30)
numeric digits 14 /* use the maximum */
conversion = 0.017453292519943 /* (2 * PI)/360 ; 360deg = 2 pi radians */
/* conversion = 1 to use radians */
signal on error /* use ERROR and SYNTAX to pass control to c:eval */
signal on syntax
parse upper arg RawInput /* accept a wide range of input styles */
StdInput = translate(RawInput,' ','(,)') /* replace separators with blanks */
parse var StdInput Function xx yy zz . /* BLANKS are our "DESIGN" seperator */
Func = left(Function,3) /* change input degrees to radians for trig functions */
if (Func='COS')|(Func='SIN')|(Func='TAN') then xx = xx * conversion
if Func = 'LOG' then Function = 'LOG10' /* use Log as base10 log function name */
if (yy ~= '') then do
if Func = 'DEG' then do /* allows 1 digit input by correcting to two digit leading zero ie: dd.mmss (decimal seconds are allowed */
yy = right(yy,2,0)
if index(zz,'.') ~= 3 then zz = right(zz,length(zz)+1,0)
operand = xx'.'yy || zz
end
else operand = xx','yy /* two part operand, comma seperated */
end
else operand = xx
interpret Value '=' Function'('Operand')' /* generic and all purpose function call */
Func = left(Function,4) /* correct output radians to degrees in Arc Trig functions*/
if (Func='ACOS')|(Func='ASIN')|(Func='ATAN') then Value = Value/Conversion
echo ' => 'Value '0a'x /* our answer */
exit /* normal end program */
error: /* if all else fails */
syntax: /* or non_rexxmath.library problem */
address command 'eval' RawInput 'lformat = " => %N *N"'
exit /* and quit */
DEG: procedure /* convert Deg Min Sec to decimal degrees */
parse arg Deg '.' Min +2 Sec
return Deg + Min/60 + Sec/3600
DMS: procedure /* convert decimal degs to Degs Min Sec */
parse upper arg Deg
cut = index(Deg,'.')
parse arg Deg =cut MinSec
Min = MinSec * 60
cut = index(Min,'.')
parse var Min Min =cut Sec
return Deg Min Sec*60
exit /* end script eval.rexx */